// app.js
App({
  onLaunch() {
    const accountInfo = wx.getAccountInfoSync();
    switch (accountInfo.miniProgram.envVersion) {
      case 'develop': // 开发版
        this.globalData.BaseUrl = 'https://gatewaytest.tongdow.com/api/v1';
        this.globalData.wsUrl = 'wss://gateway.tongdow.com/api/v1/ws';
        this.globalData.fsUrl = 'https://fdfstest.tongdow.com';
        break;
      case 'tral': // 体验版
        this.globalData.BaseUrl = 'https://gatewaytest.tongdow.com/api/v1';
        this.globalData.wsUrl = 'wss://gateway.tongdow.com/api/v1/ws';
        this.globalData.fsUrl = 'https://fdfstest.tongdow.com';
        break;
      case 'release': // 正式版
        this.globalData.BaseUrl = 'https://gateway.tongdow.com/api/v1';
        this.globalData.wsUrl = 'wss://gateway.tongdow.com/api/v1/ws';
        this.globalData.fsUrl = 'https://fdfs.tongdow.com';
        break;
    }
    wx.onAppRoute((res) => {
      console.log(res)
      let token = wx.getStorageSync('token')
      let tokenExpire = wx.getStorageSync('tokenExpire');
      let currentTime = new Date().getTime();
      if (tokenExpire && currentTime - new Date(tokenExpire).getTime() > 0) {
        wx.removeStorageSync('token')
        wx.removeStorageSync('tokenExpire')
        wx.removeStorageSync('userInfo')
        wx.removeStorageSync('userService')
      } else {
        if (token) {
          if (res.path == 'packageA/pages/login/index' || res.path == 'packageA/pages/register/index') {
            wx.switchTab({
              url: '/pages/index/index',
            })
          }
        }
      }
   })
  },
  globalData: {
    BaseUrl: 'https://gatewaytest.tongdow.com/api/v1',
    wsUrl: 'wss://gateway.tongdow.com/api/v1/ws',
    fsUrl: 'https://fdfstest.tongdow.com',
  }
})
